package cn.fly.web.controller;

import cn.fly.Util.thread.ThreadPoolExecutorUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.concurrent.ThreadPoolExecutor;

@Controller
public class AccountController {


    @RequestMapping(value = "/signin", method = RequestMethod.GET)
    public String login() {
        return "signIn";

    }

    @RequestMapping(value = "/test2", method = RequestMethod.GET)
    public String test2(HttpSession session, String username, String userpass) throws Exception {

        ThreadPoolExecutor executor = ThreadPoolExecutorUtil.getExecutor();
        for (int i = 0; i < 15; i++) {
            MyTask myTask = new MyTask(i);
            executor.execute(myTask);
            System.out.println("==线程池中线程数：" + executor.getPoolSize() + "，队列中等待执行的任务数：" +
                    executor.getQueue().size() + "，已执行完任务数：" + executor.getCompletedTaskCount());
        }
        return "signIn";
    }

    class MyTask implements Runnable {
        private int taskNum;

        public MyTask(int num) {
            this.taskNum = num;
        }

        @Override
        public void run() {
            System.out.println("正在执行task "+taskNum);
            try {
                Thread.currentThread().sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("task "+taskNum+"执行完毕");
        }
    }

//    @RequestMapping(value = "/hotUpdate", method = RequestMethod.GET)
//    public String index(HttpSession session, String username, String userpass) throws Exception {
//
//
//        //service 可以修改
//        Class clazz = accountService.getClass();
//        Field field = clazz.getDeclaredField("name");
//        field.setAccessible(true);
//        field.set(accountService, "成功");
//
//        //父类的可以修改，但是没法传给子类
//        Class baseClazz = baseServiceImpl.getClass();
//        Field baseUrlField = baseClazz.getDeclaredField("baseurl");
//        baseUrlField.setAccessible(true);
//        baseUrlField.set(baseServiceImpl, "www.tt.com");
//
//        accountService.findAcc(username);
//
//        System.out.println(baseServiceImpl.getBaseurl());
//
//        return "signIn";
//
//    }


}
